<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="add">存储数据</button>
    <button id="read">读取数据</button>
    <button id="del">删除数据</button>
    <button id="clear">清空数据</button>
    <script>
        var add=document.querySelector('#add')
        var read=document.querySelector('#read')
        var del=document.querySelector('#del')
        var clear=document.querySelector('#clear')

        add.onclick=function(){
            sessionStorage.setItem('name','张三')
            sessionStorage.setItem('user',JSON.stringify({
                name:'jack',age:20,city:'北京'
            }))
        }
        read.onclick=function(){
            console.log(sessionStorage.getItem('name'));
            console.log(JSON.parse(sessionStorage.getItem('user')||'{}'));
            
            
        }
        del.onclick=function(){
            sessionStorage.removeItem('name')
        }
        clear.onclick=function(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>